#include "mytask.h"
#include <QDebug>
#include <QThread>
#include <QCoreApplication>
 
MyTask::MyTask(QObject *parent) : QObject(parent) {}
 
void MyTask::doWork() {
    //这里打印出实际执行的线程
    if(QThread::currentThread() == QCoreApplication::instance()->thread())
        qDebug() << "当前任务运行在主线程:" << QThread::currentThread();
    else
        qDebug() << "当前任务运行在新线程:" << QThread::currentThread();
}
 
//仅是对stared信号的封装，可通过调用该函数触发stared信号
void MyTask::start() {
    emit started();
}
